﻿<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>创建NetFramework自宿主项目</title>
    <script type="text/javascript" src="../../Content/highlighter/scripts/shCore.js"></script>
    <script type="text/javascript" src="../../Content/highlighter/scripts/shBrushCSharp.js"></script>
    <script type="text/javascript" src="../../Content/highlighter/scripts/shBrushXml.js"></script>
    <link type="text/css" rel="stylesheet" href="../../Content/highlighter/styles/shCore.css" />
    <link type="text/css" rel="stylesheet" href="../../Content/highlighter/styles/shCoreEclipse.css" />
    <script type="text/javascript">SyntaxHighlighter.all();</script>
</head>
<body>
    <h3>利用Owin.Host服务器自宿主</h3>
    <p>
        <b>1.首先建立基于.net framework 4.0+的控制台应用程序</b><br />
    </p>
    <p>
        <b>2.安装NFinal.Host nuget包</b><br />
    </p>
    <p>
        <b>3.配置Startup类</b><br />
        <pre class="brush: csharp">
            using Owin;

            public class Startup
            {
                public void Configuration(IAppBuilder appBuilder)
                {
                    appBuilder.Use&lt;NFinal.Middleware.OwinMiddleware>();
                    appBuilder.UseStaticFiles();
                }
            }
        </pre>
    </p>
    <p>
        <b>4.启动Owin服务器</b><br />
        <pre class="brush: csharp">
            using NFinal;

            public class Program
            {
                public static void Main(string[] args)
                {
            
                    bool debug = true;
                    string url = null;
                    if (debug)
                    {
                        url = "http://localhost:8083";
                    }
                    else
                    {
                        url = "http://localhost:80";
                    }
                    using (Microsoft.Owin.Hosting.WebApp.Start&lt;NFinalServerSample.Startup>(url))
                    {
                        Console.WriteLine("服务器已经启动");
                        Console.ReadKey();
                    }
                }
            }
       </pre>
    </p>
    <b>5.修改Web.Config,</b><br/>
    添加runAllManagedModulesForAllRequests,允许自定义Middleware<br/>
    <pre class="brush:xml;">
        &lt;configuration>
            &lt;system.webServer>
                &lt;modules runAllManagedModulesForAllRequests="true">
                &lt;/modules>
            &lt;/system.webServer>
        &lt;/configuration>
    </pre>
    <b>5.全局配置文件nfinal.json</b>
    <p>
        在该项目默认输出目录中创建nfinal.json。<br />
        一般位于bin\Debug\nfinal.json.
    </p>
    <b>6.插件配置文件plug.json</b>
    <p>
        该文件位于该项目输出目录中的Plugs目录下的插件目录中。<br />
        一般位于bin\Debug\Plugs\[插件目录]\plug.json<br />
        在该配置文件中需要指定dll插件的文件路径用于该项目加载.
    </p>
</body>
</html>